<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>pbliteserializer_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_proto2_pbliteserializer_test.js.html">pbliteserializer_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.proto2.PbLiteSerializerTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.proto2.PbLiteSerializerTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.proto2.PbLiteSerializer&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>goog.require(&#39;proto2.TestAllTypes&#39;);
<a name="line21"></a>
<a name="line22"></a>function testSerializationAndDeserialization() {
<a name="line23"></a>  var message = createPopulatedMessage();
<a name="line24"></a>
<a name="line25"></a>  // Serialize.
<a name="line26"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line27"></a>  var pblite = serializer.serialize(message);
<a name="line28"></a>
<a name="line29"></a>  assertTrue(goog.isArray(pblite));
<a name="line30"></a>
<a name="line31"></a>  // Assert that everything serialized properly.
<a name="line32"></a>  assertEquals(101, pblite[1]);
<a name="line33"></a>  assertEquals(&#39;102&#39;, pblite[2]);
<a name="line34"></a>  assertEquals(103, pblite[3]);
<a name="line35"></a>  assertEquals(&#39;104&#39;, pblite[4]);
<a name="line36"></a>  assertEquals(105, pblite[5]);
<a name="line37"></a>  assertEquals(&#39;106&#39;, pblite[6]);
<a name="line38"></a>  assertEquals(107, pblite[7]);
<a name="line39"></a>  assertEquals(&#39;108&#39;, pblite[8]);
<a name="line40"></a>  assertEquals(109, pblite[9]);
<a name="line41"></a>  assertEquals(&#39;110&#39;, pblite[10]);
<a name="line42"></a>  assertEquals(111.5, pblite[11]);
<a name="line43"></a>  assertEquals(112.5, pblite[12]);
<a name="line44"></a>  assertEquals(1, pblite[13]); // true is serialized as 1
<a name="line45"></a>  assertEquals(&#39;test&#39;, pblite[14]);
<a name="line46"></a>  assertEquals(&#39;abcd&#39;, pblite[15]);
<a name="line47"></a>
<a name="line48"></a>  assertEquals(111, pblite[16][17]);
<a name="line49"></a>  assertEquals(112, pblite[18][1]);
<a name="line50"></a>
<a name="line51"></a>  assertTrue(pblite[19] === undefined);
<a name="line52"></a>  assertTrue(pblite[20] === undefined);
<a name="line53"></a>
<a name="line54"></a>  assertEquals(proto2.TestAllTypes.NestedEnum.FOO, pblite[21]);
<a name="line55"></a>
<a name="line56"></a>  assertEquals(201, pblite[31][0]);
<a name="line57"></a>  assertEquals(202, pblite[31][1]);
<a name="line58"></a>  assertEquals(&#39;foo&#39;, pblite[44][0]);
<a name="line59"></a>  assertEquals(&#39;bar&#39;, pblite[44][1]);
<a name="line60"></a>
<a name="line61"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line62"></a>  // Deserialize.
<a name="line63"></a>  var messageCopy =
<a name="line64"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pblite);
<a name="line65"></a>
<a name="line66"></a>  assertNotEquals(messageCopy, message);
<a name="line67"></a>
<a name="line68"></a>  assertDeserializationMatches(messageCopy);
<a name="line69"></a>}
<a name="line70"></a>
<a name="line71"></a>function testZeroBasedSerializationAndDeserialization() {
<a name="line72"></a>  var message = createPopulatedMessage();
<a name="line73"></a>
<a name="line74"></a>  // Serialize.
<a name="line75"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line76"></a>  serializer.setZeroIndexed(true);
<a name="line77"></a>
<a name="line78"></a>  var pblite = serializer.serialize(message);
<a name="line79"></a>
<a name="line80"></a>  assertTrue(goog.isArray(pblite));
<a name="line81"></a>
<a name="line82"></a>  // Assert that everything serialized properly.
<a name="line83"></a>  assertEquals(101, pblite[0]);
<a name="line84"></a>  assertEquals(&#39;102&#39;, pblite[1]);
<a name="line85"></a>  assertEquals(103, pblite[2]);
<a name="line86"></a>  assertEquals(&#39;104&#39;, pblite[3]);
<a name="line87"></a>  assertEquals(105, pblite[4]);
<a name="line88"></a>  assertEquals(&#39;106&#39;, pblite[5]);
<a name="line89"></a>  assertEquals(107, pblite[6]);
<a name="line90"></a>  assertEquals(&#39;108&#39;, pblite[7]);
<a name="line91"></a>  assertEquals(109, pblite[8]);
<a name="line92"></a>  assertEquals(&#39;110&#39;, pblite[9]);
<a name="line93"></a>  assertEquals(111.5, pblite[10]);
<a name="line94"></a>  assertEquals(112.5, pblite[11]);
<a name="line95"></a>  assertEquals(1, pblite[12]); // true is serialized as 1
<a name="line96"></a>  assertEquals(&#39;test&#39;, pblite[13]);
<a name="line97"></a>  assertEquals(&#39;abcd&#39;, pblite[14]);
<a name="line98"></a>
<a name="line99"></a>  assertEquals(111, pblite[15][16]);
<a name="line100"></a>  assertEquals(112, pblite[17][0]);
<a name="line101"></a>
<a name="line102"></a>  assertTrue(pblite[18] === undefined);
<a name="line103"></a>  assertTrue(pblite[19] === undefined);
<a name="line104"></a>
<a name="line105"></a>  assertEquals(proto2.TestAllTypes.NestedEnum.FOO, pblite[20]);
<a name="line106"></a>
<a name="line107"></a>  assertEquals(201, pblite[30][0]);
<a name="line108"></a>  assertEquals(202, pblite[30][1]);
<a name="line109"></a>  assertEquals(&#39;foo&#39;, pblite[43][0]);
<a name="line110"></a>  assertEquals(&#39;bar&#39;, pblite[43][1]);
<a name="line111"></a>
<a name="line112"></a>  // Deserialize.
<a name="line113"></a>  var messageCopy =
<a name="line114"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pblite);
<a name="line115"></a>
<a name="line116"></a>  assertNotEquals(messageCopy, message);
<a name="line117"></a>
<a name="line118"></a>  assertEquals(message.getOptionalInt32(), messageCopy.getOptionalInt32());
<a name="line119"></a>  assertDeserializationMatches(messageCopy);
<a name="line120"></a>}
<a name="line121"></a>
<a name="line122"></a>function createPopulatedMessage() {
<a name="line123"></a>  var message = new proto2.TestAllTypes();
<a name="line124"></a>
<a name="line125"></a>  // Set the fields.
<a name="line126"></a>  // Singular.
<a name="line127"></a>  message.setOptionalInt32(101);
<a name="line128"></a>  message.setOptionalInt64(&#39;102&#39;);
<a name="line129"></a>  message.setOptionalUint32(103);
<a name="line130"></a>  message.setOptionalUint64(&#39;104&#39;);
<a name="line131"></a>  message.setOptionalSint32(105);
<a name="line132"></a>  message.setOptionalSint64(&#39;106&#39;);
<a name="line133"></a>  message.setOptionalFixed32(107);
<a name="line134"></a>  message.setOptionalFixed64(&#39;108&#39;);
<a name="line135"></a>  message.setOptionalSfixed32(109);
<a name="line136"></a>  message.setOptionalSfixed64(&#39;110&#39;);
<a name="line137"></a>  message.setOptionalFloat(111.5);
<a name="line138"></a>  message.setOptionalDouble(112.5);
<a name="line139"></a>  message.setOptionalBool(true);
<a name="line140"></a>  message.setOptionalString(&#39;test&#39;);
<a name="line141"></a>  message.setOptionalBytes(&#39;abcd&#39;);
<a name="line142"></a>
<a name="line143"></a>  var group = new proto2.TestAllTypes.OptionalGroup();
<a name="line144"></a>  group.setA(111);
<a name="line145"></a>
<a name="line146"></a>  message.setOptionalgroup(group);
<a name="line147"></a>
<a name="line148"></a>  var nestedMessage = new proto2.TestAllTypes.NestedMessage();
<a name="line149"></a>  nestedMessage.setB(112);
<a name="line150"></a>
<a name="line151"></a>  message.setOptionalNestedMessage(nestedMessage);
<a name="line152"></a>
<a name="line153"></a>  message.setOptionalNestedEnum(proto2.TestAllTypes.NestedEnum.FOO);
<a name="line154"></a>
<a name="line155"></a>  // Repeated.
<a name="line156"></a>  message.addRepeatedInt32(201);
<a name="line157"></a>  message.addRepeatedInt32(202);
<a name="line158"></a>
<a name="line159"></a>  // Skip a few repeated fields so we can test how null array values are
<a name="line160"></a>  // handled.
<a name="line161"></a>  message.addRepeatedString(&#39;foo&#39;);
<a name="line162"></a>  message.addRepeatedString(&#39;bar&#39;);
<a name="line163"></a>  return message;
<a name="line164"></a>}
<a name="line165"></a>
<a name="line166"></a>function testDeserializationFromExternalSource() {
<a name="line167"></a>  // Test deserialization where the JSON array is initialized from something
<a name="line168"></a>  // outside the Closure proto2 library, such as the JsPbLite library, or
<a name="line169"></a>  // manually as in this test.
<a name="line170"></a>  var pblite = [
<a name="line171"></a>    , // 0
<a name="line172"></a>    101, // 1
<a name="line173"></a>    &#39;102&#39;, // 2
<a name="line174"></a>    103, // 3
<a name="line175"></a>    &#39;104&#39;, // 4
<a name="line176"></a>    105, // 5
<a name="line177"></a>    &#39;106&#39;, // 6
<a name="line178"></a>    107, // 7
<a name="line179"></a>    &#39;108&#39;, // 8
<a name="line180"></a>    109, // 9
<a name="line181"></a>    &#39;110&#39;, // 10
<a name="line182"></a>    111.5, // 11
<a name="line183"></a>    112.5, // 12
<a name="line184"></a>    1, // 13
<a name="line185"></a>    &#39;test&#39;, // 14
<a name="line186"></a>    &#39;abcd&#39;, // 15
<a name="line187"></a>    [,,,,,,,,,,,,,,,,, 111], // 16, note the 17 commas so value is index 17
<a name="line188"></a>    , // 17
<a name="line189"></a>    [, 112], // 18
<a name="line190"></a>    ,, // 19-20
<a name="line191"></a>    proto2.TestAllTypes.NestedEnum.FOO, // 21
<a name="line192"></a>    ,,,,,,,,, // 22-30
<a name="line193"></a>    [201, 202], // 31
<a name="line194"></a>    ,,,,,,,,,,,, // 32-43
<a name="line195"></a>    [&#39;foo&#39;, &#39;bar&#39;], // 44
<a name="line196"></a>    ,,,, // 45-49
<a name="line197"></a>  ];
<a name="line198"></a>
<a name="line199"></a>  // Deserialize.
<a name="line200"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line201"></a>  var messageCopy =
<a name="line202"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pblite);
<a name="line203"></a>
<a name="line204"></a>  assertDeserializationMatches(messageCopy);
<a name="line205"></a>
<a name="line206"></a>  // http://b/issue?id=2928075
<a name="line207"></a>  assertFalse(messageCopy.hasRepeatedInt64());
<a name="line208"></a>  assertEquals(0, messageCopy.repeatedInt64Count());
<a name="line209"></a>  messageCopy.repeatedInt64Array();
<a name="line210"></a>  assertFalse(messageCopy.hasRepeatedInt64());
<a name="line211"></a>  assertEquals(0, messageCopy.repeatedInt64Count());
<a name="line212"></a>
<a name="line213"></a>  // Access a nested message to ensure it is deserialized.
<a name="line214"></a>  assertNotNull(messageCopy.getOptionalNestedMessage());
<a name="line215"></a>
<a name="line216"></a>  // Verify that the pblite array itself has not been replaced by the
<a name="line217"></a>  // deserialization.
<a name="line218"></a>  assertEquals(&#39;array&#39;, goog.typeOf(pblite[16]));
<a name="line219"></a>
<a name="line220"></a>  // Update some fields and verify that the changes work with the lazy
<a name="line221"></a>  // deserializer.
<a name="line222"></a>  messageCopy.setOptionalBool(true);
<a name="line223"></a>  assertTrue(messageCopy.getOptionalBool());
<a name="line224"></a>
<a name="line225"></a>  messageCopy.setOptionalBool(false);
<a name="line226"></a>  assertFalse(messageCopy.getOptionalBool());
<a name="line227"></a>
<a name="line228"></a>  messageCopy.setOptionalInt32(1234);
<a name="line229"></a>  assertEquals(1234, messageCopy.getOptionalInt32());
<a name="line230"></a>}
<a name="line231"></a>
<a name="line232"></a>function testModifyLazyDeserializedMessage() {
<a name="line233"></a>  var pblite = [
<a name="line234"></a>    , // 0
<a name="line235"></a>    101, // 1
<a name="line236"></a>    &#39;102&#39;, // 2
<a name="line237"></a>    103, // 3
<a name="line238"></a>    &#39;104&#39;, // 4
<a name="line239"></a>    105, // 5
<a name="line240"></a>    &#39;106&#39;, // 6
<a name="line241"></a>    107, // 7
<a name="line242"></a>    &#39;108&#39;, // 8
<a name="line243"></a>    109, // 9
<a name="line244"></a>    &#39;110&#39;, // 10
<a name="line245"></a>    111.5, // 11
<a name="line246"></a>    112.5, // 12
<a name="line247"></a>    1, // 13
<a name="line248"></a>    &#39;test&#39;, // 14
<a name="line249"></a>    &#39;abcd&#39;, // 15
<a name="line250"></a>    [,,,,,,,,,,,,,,,,, 111], // 16, note the 17 commas so value is index 17
<a name="line251"></a>    , // 17
<a name="line252"></a>    [, 112], // 18
<a name="line253"></a>    ,, // 19-20
<a name="line254"></a>    proto2.TestAllTypes.NestedEnum.FOO, // 21
<a name="line255"></a>    ,,,,,,,,, // 22-30
<a name="line256"></a>    [201, 202], // 31
<a name="line257"></a>    ,,,,,,,,,,,, // 32-43
<a name="line258"></a>    [&#39;foo&#39;, &#39;bar&#39;], // 44
<a name="line259"></a>    ,,,, // 45-49
<a name="line260"></a>  ];
<a name="line261"></a>
<a name="line262"></a>  // Deserialize.
<a name="line263"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line264"></a>  var message =
<a name="line265"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pblite);
<a name="line266"></a>
<a name="line267"></a>  // Conduct some operations, ensuring that they all work as expected, even with
<a name="line268"></a>  // the lazily deserialized data.
<a name="line269"></a>  assertEquals(101, message.getOptionalInt32());
<a name="line270"></a>  message.setOptionalInt32(401);
<a name="line271"></a>  assertEquals(401, message.getOptionalInt32());
<a name="line272"></a>
<a name="line273"></a>  assertEquals(2, message.repeatedInt32Count());
<a name="line274"></a>  assertEquals(201, message.getRepeatedInt32(0));
<a name="line275"></a>  assertEquals(202, message.getRepeatedInt32(1));
<a name="line276"></a>
<a name="line277"></a>  message.clearRepeatedInt32();
<a name="line278"></a>  assertEquals(0, message.repeatedInt32Count());
<a name="line279"></a>
<a name="line280"></a>  message.addRepeatedInt32(101);
<a name="line281"></a>  assertEquals(1, message.repeatedInt32Count());
<a name="line282"></a>  assertEquals(101, message.getRepeatedInt32(0));
<a name="line283"></a>
<a name="line284"></a>  message.setUnknown(12345, 601);
<a name="line285"></a>  message.forEachUnknown(function(tag, value) {
<a name="line286"></a>    assertEquals(12345, tag);
<a name="line287"></a>    assertEquals(601, value);
<a name="line288"></a>  });
<a name="line289"></a>
<a name="line290"></a>  // Create a copy of the message.
<a name="line291"></a>  var messageCopy = new proto2.TestAllTypes();
<a name="line292"></a>  messageCopy.copyFrom(message);
<a name="line293"></a>
<a name="line294"></a>  assertEquals(1, messageCopy.repeatedInt32Count());
<a name="line295"></a>  assertEquals(101, messageCopy.getRepeatedInt32(0));
<a name="line296"></a>}
<a name="line297"></a>
<a name="line298"></a>function testModifyLazyDeserializedMessageByAddingMessage() {
<a name="line299"></a>  var pblite = [
<a name="line300"></a>    , // 0
<a name="line301"></a>    101, // 1
<a name="line302"></a>    &#39;102&#39;, // 2
<a name="line303"></a>    103, // 3
<a name="line304"></a>    &#39;104&#39;, // 4
<a name="line305"></a>    105, // 5
<a name="line306"></a>    &#39;106&#39;, // 6
<a name="line307"></a>    107, // 7
<a name="line308"></a>    &#39;108&#39;, // 8
<a name="line309"></a>    109, // 9
<a name="line310"></a>    &#39;110&#39;, // 10
<a name="line311"></a>    111.5, // 11
<a name="line312"></a>    112.5, // 12
<a name="line313"></a>    1, // 13
<a name="line314"></a>    &#39;test&#39;, // 14
<a name="line315"></a>    &#39;abcd&#39;, // 15
<a name="line316"></a>    [,,,,,,,,,,,,,,,,, 111], // 16, note the 17 commas so value is index 17
<a name="line317"></a>    , // 17
<a name="line318"></a>    [, 112], // 18
<a name="line319"></a>    ,, // 19-20
<a name="line320"></a>    proto2.TestAllTypes.NestedEnum.FOO, // 21
<a name="line321"></a>    ,,,,,,,,, // 22-30
<a name="line322"></a>    [201, 202], // 31
<a name="line323"></a>    ,,,,,,,,,,,, // 32-43
<a name="line324"></a>    [&#39;foo&#39;, &#39;bar&#39;], // 44
<a name="line325"></a>    ,,,, // 45-49
<a name="line326"></a>  ];
<a name="line327"></a>
<a name="line328"></a>  // Deserialize.
<a name="line329"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line330"></a>  var message =
<a name="line331"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pblite);
<a name="line332"></a>
<a name="line333"></a>  // Add a new nested message.
<a name="line334"></a>  var nested1 = new proto2.TestAllTypes.NestedMessage();
<a name="line335"></a>  nested1.setB(1234);
<a name="line336"></a>
<a name="line337"></a>  var nested2 = new proto2.TestAllTypes.NestedMessage();
<a name="line338"></a>  nested2.setB(4567);
<a name="line339"></a>
<a name="line340"></a>  message.addRepeatedNestedMessage(nested1);
<a name="line341"></a>
<a name="line342"></a>  // Check the new nested message.
<a name="line343"></a>  assertEquals(1, message.repeatedNestedMessageArray().length);
<a name="line344"></a>  assertTrue(message.repeatedNestedMessageArray()[0].equals(nested1));
<a name="line345"></a>
<a name="line346"></a>  // Add another nested message.
<a name="line347"></a>  message.addRepeatedNestedMessage(nested2);
<a name="line348"></a>
<a name="line349"></a>  // Check both nested messages.
<a name="line350"></a>  assertEquals(2, message.repeatedNestedMessageArray().length);
<a name="line351"></a>  assertTrue(message.repeatedNestedMessageArray()[0].equals(nested1));
<a name="line352"></a>  assertTrue(message.repeatedNestedMessageArray()[1].equals(nested2));
<a name="line353"></a>}
<a name="line354"></a>
<a name="line355"></a>function assertDeserializationMatches(messageCopy) {
<a name="line356"></a>  assertNotNull(messageCopy);
<a name="line357"></a>
<a name="line358"></a>  assertTrue(messageCopy.hasOptionalInt32());
<a name="line359"></a>  assertTrue(messageCopy.hasOptionalInt64());
<a name="line360"></a>  assertTrue(messageCopy.hasOptionalUint32());
<a name="line361"></a>  assertTrue(messageCopy.hasOptionalUint64());
<a name="line362"></a>  assertTrue(messageCopy.hasOptionalSint32());
<a name="line363"></a>  assertTrue(messageCopy.hasOptionalSint64());
<a name="line364"></a>  assertTrue(messageCopy.hasOptionalFixed32());
<a name="line365"></a>  assertTrue(messageCopy.hasOptionalFixed64());
<a name="line366"></a>  assertTrue(messageCopy.hasOptionalSfixed32());
<a name="line367"></a>  assertTrue(messageCopy.hasOptionalSfixed64());
<a name="line368"></a>  assertTrue(messageCopy.hasOptionalFloat());
<a name="line369"></a>  assertTrue(messageCopy.hasOptionalDouble());
<a name="line370"></a>  assertTrue(messageCopy.hasOptionalBool());
<a name="line371"></a>  assertTrue(messageCopy.hasOptionalString());
<a name="line372"></a>  assertTrue(messageCopy.hasOptionalBytes());
<a name="line373"></a>  assertTrue(messageCopy.hasOptionalgroup());
<a name="line374"></a>  assertTrue(messageCopy.hasOptionalNestedMessage());
<a name="line375"></a>  assertTrue(messageCopy.hasOptionalNestedEnum());
<a name="line376"></a>
<a name="line377"></a>  assertTrue(messageCopy.hasRepeatedInt32());
<a name="line378"></a>  assertFalse(messageCopy.hasRepeatedInt64());
<a name="line379"></a>  assertFalse(messageCopy.hasRepeatedUint32());
<a name="line380"></a>  assertFalse(messageCopy.hasRepeatedUint64());
<a name="line381"></a>  assertFalse(messageCopy.hasRepeatedSint32());
<a name="line382"></a>  assertFalse(messageCopy.hasRepeatedSint64());
<a name="line383"></a>  assertFalse(messageCopy.hasRepeatedFixed32());
<a name="line384"></a>  assertFalse(messageCopy.hasRepeatedFixed64());
<a name="line385"></a>  assertFalse(messageCopy.hasRepeatedSfixed32());
<a name="line386"></a>  assertFalse(messageCopy.hasRepeatedSfixed64());
<a name="line387"></a>  assertFalse(messageCopy.hasRepeatedFloat());
<a name="line388"></a>  assertFalse(messageCopy.hasRepeatedDouble());
<a name="line389"></a>  assertFalse(messageCopy.hasRepeatedBool());
<a name="line390"></a>  assertTrue(messageCopy.hasRepeatedString());
<a name="line391"></a>  assertFalse(messageCopy.hasRepeatedBytes());
<a name="line392"></a>  assertFalse(messageCopy.hasRepeatedgroup());
<a name="line393"></a>  assertFalse(messageCopy.hasRepeatedNestedMessage());
<a name="line394"></a>  assertFalse(messageCopy.hasRepeatedNestedEnum());
<a name="line395"></a>
<a name="line396"></a>  assertEquals(1, messageCopy.optionalInt32Count());
<a name="line397"></a>  assertEquals(1, messageCopy.optionalInt64Count());
<a name="line398"></a>  assertEquals(1, messageCopy.optionalUint32Count());
<a name="line399"></a>  assertEquals(1, messageCopy.optionalUint64Count());
<a name="line400"></a>  assertEquals(1, messageCopy.optionalSint32Count());
<a name="line401"></a>  assertEquals(1, messageCopy.optionalSint64Count());
<a name="line402"></a>  assertEquals(1, messageCopy.optionalFixed32Count());
<a name="line403"></a>  assertEquals(1, messageCopy.optionalFixed64Count());
<a name="line404"></a>  assertEquals(1, messageCopy.optionalSfixed32Count());
<a name="line405"></a>  assertEquals(1, messageCopy.optionalSfixed64Count());
<a name="line406"></a>  assertEquals(1, messageCopy.optionalFloatCount());
<a name="line407"></a>  assertEquals(1, messageCopy.optionalDoubleCount());
<a name="line408"></a>  assertEquals(1, messageCopy.optionalBoolCount());
<a name="line409"></a>  assertEquals(1, messageCopy.optionalStringCount());
<a name="line410"></a>  assertEquals(1, messageCopy.optionalBytesCount());
<a name="line411"></a>  assertEquals(1, messageCopy.optionalgroupCount());
<a name="line412"></a>  assertEquals(1, messageCopy.optionalNestedMessageCount());
<a name="line413"></a>  assertEquals(1, messageCopy.optionalNestedEnumCount());
<a name="line414"></a>
<a name="line415"></a>  assertEquals(2, messageCopy.repeatedInt32Count());
<a name="line416"></a>  assertEquals(0, messageCopy.repeatedInt64Count());
<a name="line417"></a>  assertEquals(0, messageCopy.repeatedUint32Count());
<a name="line418"></a>  assertEquals(0, messageCopy.repeatedUint64Count());
<a name="line419"></a>  assertEquals(0, messageCopy.repeatedSint32Count());
<a name="line420"></a>  assertEquals(0, messageCopy.repeatedSint64Count());
<a name="line421"></a>  assertEquals(0, messageCopy.repeatedFixed32Count());
<a name="line422"></a>  assertEquals(0, messageCopy.repeatedFixed64Count());
<a name="line423"></a>  assertEquals(0, messageCopy.repeatedSfixed32Count());
<a name="line424"></a>  assertEquals(0, messageCopy.repeatedSfixed64Count());
<a name="line425"></a>  assertEquals(0, messageCopy.repeatedFloatCount());
<a name="line426"></a>  assertEquals(0, messageCopy.repeatedDoubleCount());
<a name="line427"></a>  assertEquals(0, messageCopy.repeatedBoolCount());
<a name="line428"></a>  assertEquals(2, messageCopy.repeatedStringCount());
<a name="line429"></a>  assertEquals(0, messageCopy.repeatedBytesCount());
<a name="line430"></a>  assertEquals(0, messageCopy.repeatedgroupCount());
<a name="line431"></a>  assertEquals(0, messageCopy.repeatedNestedMessageCount());
<a name="line432"></a>  assertEquals(0, messageCopy.repeatedNestedEnumCount());
<a name="line433"></a>
<a name="line434"></a>  assertEquals(101, messageCopy.getOptionalInt32());
<a name="line435"></a>  assertEquals(&#39;102&#39;, messageCopy.getOptionalInt64());
<a name="line436"></a>  assertEquals(103, messageCopy.getOptionalUint32());
<a name="line437"></a>  assertEquals(&#39;104&#39;, messageCopy.getOptionalUint64());
<a name="line438"></a>  assertEquals(105, messageCopy.getOptionalSint32());
<a name="line439"></a>  assertEquals(&#39;106&#39;, messageCopy.getOptionalSint64());
<a name="line440"></a>  assertEquals(107, messageCopy.getOptionalFixed32());
<a name="line441"></a>  assertEquals(&#39;108&#39;, messageCopy.getOptionalFixed64());
<a name="line442"></a>  assertEquals(109, messageCopy.getOptionalSfixed32());
<a name="line443"></a>  assertEquals(&#39;110&#39;, messageCopy.getOptionalSfixed64());
<a name="line444"></a>  assertEquals(111.5, messageCopy.getOptionalFloat());
<a name="line445"></a>  assertEquals(112.5, messageCopy.getOptionalDouble());
<a name="line446"></a>  assertEquals(true, messageCopy.getOptionalBool());
<a name="line447"></a>  assertEquals(&#39;test&#39;, messageCopy.getOptionalString());
<a name="line448"></a>  assertEquals(&#39;abcd&#39;, messageCopy.getOptionalBytes());
<a name="line449"></a>  assertEquals(111, messageCopy.getOptionalgroup().getA());
<a name="line450"></a>
<a name="line451"></a>  assertEquals(112, messageCopy.getOptionalNestedMessage().getB());
<a name="line452"></a>
<a name="line453"></a>  assertEquals(proto2.TestAllTypes.NestedEnum.FOO,
<a name="line454"></a>      messageCopy.getOptionalNestedEnum());
<a name="line455"></a>
<a name="line456"></a>  assertEquals(201, messageCopy.getRepeatedInt32(0));
<a name="line457"></a>  assertEquals(202, messageCopy.getRepeatedInt32(1));
<a name="line458"></a>}
<a name="line459"></a>
<a name="line460"></a>function testMergeFromLazyTarget() {
<a name="line461"></a>  var serializer = new goog.proto2.PbLiteSerializer();
<a name="line462"></a>
<a name="line463"></a>  var source = new proto2.TestAllTypes();
<a name="line464"></a>  var nested = new proto2.TestAllTypes.NestedMessage();
<a name="line465"></a>  nested.setB(66);
<a name="line466"></a>  source.setOptionalNestedMessage(nested);
<a name="line467"></a>  source.setOptionalInt32(32);
<a name="line468"></a>  source.setOptionalString(&#39;foo&#39;);
<a name="line469"></a>  source.setOptionalNestedEnum(proto2.TestAllTypes.NestedEnum.FOO);
<a name="line470"></a>  source.addRepeatedInt32(2);
<a name="line471"></a>
<a name="line472"></a>  var target = new proto2.TestAllTypes();
<a name="line473"></a>  nested = new proto2.TestAllTypes.NestedMessage();
<a name="line474"></a>  nested.setC(77);
<a name="line475"></a>  target.setOptionalNestedMessage(nested);
<a name="line476"></a>  target.setOptionalInt64(&#39;64&#39;);
<a name="line477"></a>  target.setOptionalString(&#39;bar&#39;);
<a name="line478"></a>  target.setOptionalNestedEnum(proto2.TestAllTypes.NestedEnum.BAR);
<a name="line479"></a>  target.addRepeatedInt32(1);
<a name="line480"></a>  var pbliteTarget = serializer.serialize(target);
<a name="line481"></a>  var lazyTarget =
<a name="line482"></a>      serializer.deserialize(proto2.TestAllTypes.getDescriptor(), pbliteTarget);
<a name="line483"></a>
<a name="line484"></a>  var expected = new proto2.TestAllTypes();
<a name="line485"></a>  nested = new proto2.TestAllTypes.NestedMessage();
<a name="line486"></a>  nested.setB(66);
<a name="line487"></a>  nested.setC(77);
<a name="line488"></a>  expected.setOptionalNestedMessage(nested);
<a name="line489"></a>  expected.setOptionalInt32(32);
<a name="line490"></a>  expected.setOptionalInt64(&#39;64&#39;);
<a name="line491"></a>  expected.setOptionalString(&#39;foo&#39;);
<a name="line492"></a>  expected.setOptionalNestedEnum(proto2.TestAllTypes.NestedEnum.FOO);
<a name="line493"></a>  expected.addRepeatedInt32(1);
<a name="line494"></a>  expected.addRepeatedInt32(2);
<a name="line495"></a>
<a name="line496"></a>  lazyTarget.mergeFrom(source);
<a name="line497"></a>  assertTrue(&#39;expected and lazyTarget are equal after mergeFrom&#39;,
<a name="line498"></a>      lazyTarget.equals(expected));
<a name="line499"></a>}
</pre>


</body>
</html>
